package com.atung.merchant.controller;

import com.atung.merchant.config.security.JwtTokenUtil;
import com.atung.merchant.dto.AuthUserEntity;
import com.atung.merchant.result.ApiResult;
import com.atung.merchant.service.AuthSecurityService;
import com.atung.merchant.service.AuthServiceImpl;
import com.atung.merchant.vo.LoginRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @author Administrator
 */
@RequestMapping("/api/auth")
@RestController
@Api(tags = "认证中心")
public class AuthController {

    @Resource
    private AuthServiceImpl authService;
    private final AuthenticationManager authenticationManager;

    public AuthController(AuthenticationManager authenticationManager) {
        this.authenticationManager = authenticationManager;
    }

    @PostMapping("/login")
    @ApiOperation("登录")
    public ApiResult login(@RequestBody @Valid LoginRequest loginRequest,HttpServletRequest httpServletRequest) {
        return  authService.userAuthLoginByNameService(loginRequest, httpServletRequest );
    }
}
